package practice.ferry;

import java.util.Scanner;

public class Main {

	int[][]solution;
	int[] cars;
	int[] total;
	int numcars;
	int length;

	public Main() {
		Scanner s =  new Scanner (System.in);
		int numCases = s.nextInt();
		cars=new int[10000];
		total=new int[10000];
		total[0]=0;
		solution = new int[10000][10001];


		for (int i =0; i < numCases; i++){
			numcars=0;
			length = s.nextInt()*100;
			int carlength=s.nextInt();
			while (carlength!=0){
				cars[numcars]=carlength;
				total[numcars+1]=total[numcars]+carlength;
				carlength=s.nextInt();
				numcars++;
			}
			for(int j=0; j < numcars;j++)
				for (int k=0; k < length+1; k++)
					solution[j][k]=-1;
			if (numcars>0){
				solve(0,length);
				System.out.println(numSolve(0,length));
				printSolve(0,length);
			}
			else
				System.out.println(0);
		}
	}
	public int solve(int car, int left){
		if (car==numcars ||  left<0 || total[car]+left-length>length)
			return 0;
		if (solution[car][left]==-1){
			solution[car][left]=Math.max(solve(car+1,left),cars[car]+solve(car+1,left-cars[car]));
		}
		return solution[car][left];
	}
	public int numSolve(int car,int left){
		//If Car will fit on left
		if (left-cars[car]>=0){
			//Total used - num used on left = num used on right   and there are cars left
			if (total[car+1]-(length-left)<=length && car<numcars-1){
				//If the max is on the right
				if (solution[car][left]==solution[car+1][left]){
					return numSolve(car+1,left)+1;
				}
				//If the max is on the left.
				else{
					return numSolve(car+1,left-cars[car])+1;
				}
			}
			//If there is no room on the right
			else{
				//If there are more cars.
				if (car < numcars-1)
					return numSolve(car+1,left-cars[car])+1;
				else
					return 1;
			}
		}
		//If car will fit on the right
		else if (total[car+1]-(length-left)<=length){
			if (car < numcars-1){
				return numSolve(car+1,left)+1;
			}
			else
				return 1;
		}
		return 0;
	}
	public void printSolve(int car, int left){
		//If Car will fit on left
		if (left-cars[car]>=0){
			//Total used - num used on left = num used on right   and there are cars left
			if (total[car+1]-(length-left)<=length && car<numcars-1){
				//If the max is on the right
				if (solution[car][left]==solution[car+1][left]){
					System.out.println("port");
					printSolve(car+1,left);
				}
				//If the max is on the left.
				else{
					System.out.println("starboard");
					printSolve(car+1,left-cars[car]);
				}
			}
			//If there is no room on the right
			else{
				System.out.println("starboard");
				//If there are more cars.
				if (car < numcars-1)
					printSolve(car+1,left-cars[car]);
			}
		}
		//If car will fit on the right
		else if (total[car+1]-(length-left)<=length){
			System.out.println("port");
			if (car < numcars-1)
				printSolve(car+1,left);
		}
	}

	public static void main(String[] args) {
		new Main();
	}

}
